package com.foo.web.controller.wechat;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.foo.common.annotation.Log;
import com.foo.common.enums.BusinessType;
import com.foo.wechat.domain.WxPoultry;
import com.foo.wechat.service.IWxPoultryService;
import com.foo.common.core.controller.BaseController;
import com.foo.common.core.domain.AjaxResult;
import com.foo.common.utils.poi.ExcelUtil;
import com.foo.common.core.page.TableDataInfo;

/**
 * 家禽管理Controller
 * 
 * @author foo
 * @date 2025-11-12
 */
@Controller
@RequestMapping("/wechat/WxPoultry")
public class WxPoultryController extends BaseController
{
    private String prefix = "wechat/WxPoultry";

    @Autowired
    private IWxPoultryService wxPoultryService;

    @RequiresPermissions("wechat:WxPoultry:view")
    @GetMapping()
    public String WxPoultry()
    {
        return prefix + "/WxPoultry";
    }

    /**
     * 查询家禽管理列表
     */
    @RequiresPermissions("wechat:WxPoultry:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxPoultry wxPoultry)
    {
        startPage();
        List<WxPoultry> list = wxPoultryService.selectWxPoultryList(wxPoultry);
        return getDataTable(list);
    }

    /**
     * 导出家禽管理列表
     */
    @RequiresPermissions("wechat:WxPoultry:export")
    @Log(title = "家禽管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxPoultry wxPoultry)
    {
        List<WxPoultry> list = wxPoultryService.selectWxPoultryList(wxPoultry);
        ExcelUtil<WxPoultry> util = new ExcelUtil<WxPoultry>(WxPoultry.class);
        return util.exportExcel(list, "WxPoultry");
    }

    /**
     * 家禽管理详情
     */
    @GetMapping("/detail/{poultryId}")
    public String detail(@PathVariable("poultryId") Long poultryId, ModelMap mmap)
    {
        WxPoultry wxPoultry = wxPoultryService.selectWxPoultryById(poultryId);
        mmap.put("wxPoultry", wxPoultry);
        return prefix + "/detail";
    }


    /**
     * 新增家禽管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存家禽管理
     */
    @RequiresPermissions("wechat:WxPoultry:add")
    @Log(title = "家禽管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxPoultry wxPoultry)
    {
        return toAjax(wxPoultryService.insertWxPoultry(wxPoultry));
    }

    /**
     * 修改家禽管理
     */
    @GetMapping("/edit/{poultryId}")
    public String edit(@PathVariable("poultryId") Long poultryId, ModelMap mmap)
    {
        WxPoultry wxPoultry = wxPoultryService.selectWxPoultryById(poultryId);
        mmap.put("wxPoultry", wxPoultry);
        return prefix + "/edit";
    }

    /**
     * 修改保存家禽管理
     */
    @RequiresPermissions("wechat:WxPoultry:edit")
    @Log(title = "家禽管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxPoultry wxPoultry)
    {
        return toAjax(wxPoultryService.updateWxPoultry(wxPoultry));
    }

    /**
     * 删除家禽管理
     */
    @RequiresPermissions("wechat:WxPoultry:remove")
    @Log(title = "家禽管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxPoultryService.deleteWxPoultryByIds(ids));
    }
}
